---@coding utf8

---@brief 深拷贝辅助函数
---@param src any
---@return any
local function _internal_deep_clone(src)
    local tar = nil
    if type(src) == "table" then
        tar = {}
        for k, v in pairs(src) do
            ---@diagnostic disable-next-line: unused-function
            tar[_internal_deep_clone(k)] = _internal_deep_clone(v)
        end
    else
        tar = src
    end
    return tar
end

---@brief 对src_table进行深拷贝
---@param src_table table
local function deep_clone(src_table)
    local result = {}
---@diagnostic disable-next-line: unused-function
    result = _internal_deep_clone(src_table)
    return result
end



---@brief 合并两个table
--- 1.如果left和right有重复部分，right将覆盖left
---@param left table
---@param right table
local function merge(left, right)
    local result = {}
    for k, v in pairs(left) do
        result[k] = v
    end
    for k, v in right do
        result[k] = v
    end
    return result
end

---@brief 合并两个table，输出结果是深拷贝
---@param left table
---@param right table
---@return table
local function deep_merge(left, right)
    local result = {}
    for k, v in pairs(left) do
        result[_internal_deep_clone(k)] = _internal_deep_clone(v)
    end
    for k, v in pairs(right) do
        result[_internal_deep_clone(k)] = _internal_deep_clone(v)
    end
    return result
end

---@brief 将left中和right重叠的部分使用right覆盖
---@param left table
---@param right table
local function value_assign(left, right)
    for k, v in pairs(right) do
        left[k] = v
    end
end

---@brief 将right的全部字段深拷贝到left上
--- 1.需要外部自己保证k是基础类型(不会对k进行深拷贝)
---@param left table
---@param right table
local function deep_assign(left, right)
    for k, v in pairs(right) do
        left[k] = _internal_deep_clone(right[k])
    end
end






